﻿using Microsoft.AspNetCore.Mvc;
using MVCCore.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MVCCore.Components
{
    public class TopMoiveList : ViewComponent
    {
        private readonly MVCCoreContext db;

        public TopMoiveList(MVCCoreContext mVCCoreContext) {
            db = mVCCoreContext;
        }

        public IViewComponentResult Invoke(int top) {
            var item = new List<Movie>();
            item = GetTopMovieList(top);
            return View(item);
        }

        private List<Movie> GetTopMovieList(int top)
        {
            return db.Movie.Take(top).ToList();
        }
    }
}
